import {setItem, updateItem, getItem} from "jvyou-storage-utils";
import {tokenName} from "@/config/request-config.ts";

export const setToken = (token: string, isSession?: boolean) => setItem(tokenName, token, isSession || false)

export const updateToken = (currentToken: string, isSession?: boolean) => updateItem(tokenName, () => currentToken, isSession || false)

export const getToken = (): string | null => {
  const token = getItem(tokenName, false)
  const tempToken = getItem(tokenName, true)
  return token || tempToken || ''
}